<?php
error_reporting (E_ALL ^ E_NOTICE);/* sua thanh 0*/
include_once($_SERVER['DOCUMENT_ROOT'] . '/htqlmba/models/m_donvi.php');
include_once($_SERVER['DOCUMENT_ROOT'] . '/htqlmba/controls/c_capnhatdonvi.php');
?>

<script type="text/javascript">

    // Function lay gia tri radio button "chon".
    function getValue(id) {
        document.capnhatdonvi.txtmadv.value = document.getElementById("madv" + id).innerHTML;
        document.capnhatdonvi.txttendv.value = document.getElementById("tendv" + id).innerHTML;
        document.capnhatdonvi.txtdiachidv.value = document.getElementById("diachidv" + id).innerHTML;
        document.capnhatdonvi.txtlienhedv.value = document.getElementById("lienhedv" + id).innerHTML;
        document.capnhatdonvi.txttentk.value = document.getElementById("tentk" + id).innerHTML;
		
        document.capnhatdonvi.txtmatkhau.value = document.getElementById("matkhau" + id).innerHTML;
        document.capnhatdonvi.txtmatkhau2.value = document.getElementById("matkhau" + id).innerHTML;
	    document.capnhatdonvi.txtquyen.value = document.getElementById("quyen" + id).innerHTML;
        // chuyen mau cac textfield tendv,diachidv,lienhedv thanh mau trang', va cho phep sua doi thong tin
        document.capnhatdonvi.txtmadv.readOnly = true;
        document.capnhatdonvi.txtmadv.style.backgroundColor = '#cccccc';
        document.capnhatdonvi.txttendv.style.backgroundColor = '#FFFFFF';
        document.capnhatdonvi.txtdiachidv.style.backgroundColor = '#FFFFFF';
        document.capnhatdonvi.txtlienhedv.style.backgroundColor = '#FFFFFF';
        document.capnhatdonvi.txttentk.style.backgroundColor = '#FFFFFF';
        document.capnhatdonvi.txtmatkhau.style.backgroundColor = '#FFFFFF';
		document.capnhatdonvi.txtmatkhau2.style.backgroundColor = '#FFFFFF';
        document.capnhatdonvi.btnsuadv.disabled = false;
        document.capnhatdonvi.btnxoadv.disabled = false;
        document.capnhatdonvi.txttendv.readOnly = false;
        document.capnhatdonvi.txtdiachidv.readOnly = false;
        document.capnhatdonvi.txtlienhedv.readOnly = false;
        document.capnhatdonvi.txttentk.readOnly = false;
        document.capnhatdonvi.txtmatkhau.readOnly = false;
        document.capnhatdonvi.txtquyen.disabled = false;
		document.capnhatdonvi.btnthemdv.disabled = true;
    }
	function xoadulieumk()
	{
		document.capnhatdonvi.txtmatkhau.value = "";
	}
	function xoadulieumk2()
	{
		document.capnhatdonvi.txtmatkhau2.value = "";
	}
	
// fuction hien bang xac nhan truoc khi xoa don vi
function confirmDelete(){
    if (confirm("Bạn có chắc muốn xóa đơn vị này không? Lưu ý: tất cả máy biến áp của đơn vị này sẽ bị xóa !")){
        return true;
    } 
    return false;
    
}


</script>
<link href="/htqlmba/libraries/css/capnhatdv.css" type="text/css" rel="stylesheet">
<!-- Than form chuong trinh xu ly -->
<div class="bodyStyle">
    <form name="capnhatdonvi" method="post" action="">
        <!-- Bang hien thi -->  
        <table align="center" class="font" width="900" border="0" cellspacing="0" cellpadding="0">
            <tr bgcolor="#dae9f3">
                <td align="left" class="TableHeader1" > &equiv; Cập nhật đơn vị </td>
            </tr>
            <tr bgcolor="#dae9f3">
                <td colspan="3" valign="top">
                    <table width="793" border="0" align="center" >
                        <tr>
                            <td width="124" align="right" >Mã đơn vị : </td>
                            <td width="263" align="left" ><input name="txtmadv" type="text" id="txtmadv"  size="10" maxlength="100"  ><span style="color:red"> <?php echo $madvErr; ?></span><br>
                          </td>
                     <td align="right" >Địa chỉ đơn vị : </td>
                            <td align="left"><input name="txtdiachidv" type="text" id="txtdiachidv"  size="40" maxlength="100"  /></td>
                        </tr>
                                
                        <tr>
                            <td align="right">Tên đơn vị : </td>
                            <td><input name="txttendv" type="text" id="txttendv" size="40" maxlength="100"  ><span class="error"><?php echo $tendvErr2; ?></span><br>

                            </td>
                            <td align="right" >Mật khẩu : </td>
                            <td align="left" ><input name="txtmatkhau" type="password" id="txtmatkhau" size="40" maxlength="100" onclick="xoadulieumk()">
                            <span class="error"><?php echo  $matkhauErr; ?></span>
                            </td>
                           
                        </tr>        

                        <tr>
                            <td align="right">Tên tài khoản : </td>
                            <td><input name="txttentk" type="text" id="txttentk"  size="40" maxlength="100" ><span class="error"><?php echo $tentkErr2; ?></span><br></td>
                            <td align="right" >Xác nhận mật khẩu : </td>
                            <td align="left" ><input name="txtmatkhau2" type="password" id="txtmatkhau2" size="40" maxlength="100"   onclick="xoadulieumk2()">
                     <span class="error"><?php echo  $matkhauErr2; ?></span>  </td>
                            
                        </tr>
                        
                        
                        <tr>
                            <td align="right"><span >Thông tin liên hệ : </span></td>
                            <td><span >
                                    <input name="txtlienhedv" type="text" id="txtlienhedv"  size="40" maxlength="100"  >
                                </span><br>
                            </td>
                            <td align="right" >Quyền : </td>
                            <td align="left" ><select name="txtquyen" id="txtquyen" >
                                    <option selected></option>
                                    <option value="1">Phòng KH-KT (1)</option>
                                    <option value="2">Đơn vị thành viên (2)</option>
                                    <option value="3">Đơn vị nhập số liệu (3)</option>
                                </select>
								<span style="color:red"><?php echo $quyenErr;?></span>
                            </td>
                        </tr>
                        
                        <tr align="center">
                            <td colspan="4" class="btn_x" id="btn_x" >
                                <input type="submit" name="btnthemdv2" id="btnthemdv2" value="Thêm">
                                <input type="submit" name="btnsuadv" id="btnsuadv" value="Sửa" disabled="true">
                                <input type="submit" name="btnxoadv" id="btnxoadv" value="Xóa"  disabled="true" onClick=" return confirmDelete()">
                          </td>
                        </tr>
                        
                    </table>
                </td>
            </tr>
        </table>
        </br>


        <!-- Lay du lieu tu bang don vi va hien thi -->
        <?php
        $donvi = new DonVi();
        $result = $donvi->dsDonVi();
        echo "<table align='center' width='900' border='0' cellspacing='0' cellpadding='0' ";
        echo "<tr >";
        echo "<td align='left' class='TableHeader1'> &equiv; Danh sách đơn vị</td>";
        echo "</tr>";
        echo "<tr >";
        echo "<td colspan='3' valign='top'><table width='900' border='0' cellpadding='0' cellspacing='0'>";
        echo "<tr>";
        echo "<td width='30' align='center' class='TableHeader' >STT</td>";
        echo "<td width='400' align='center' class='TableHeader' >Mã đơn vị </td>";
        echo "<td width='900' align='center' class='TableHeader' >Tên đơn vị </td>";
        echo "<td width='800' align='center' class='TableHeader'>Địa chỉ đơn vị </td>";
        echo "<td width='600' align='center' class='TableHeader'>Thông tin liên hệ </td>";
        echo "<td width='600' align='center' class='TableHeader'>Tên tài khoản </td>";
        echo "<td width='600' align='center' class='TableHeader'>Mật khẩu </td>";
        echo "<td width='50' align='center' class='TableHeader'>Quyền </td>";
           echo "</tr>";

        $num = mysql_num_rows($result);
        $i = 0;
        echo "<tbody style='display:none;'>";
        while ($row = mysql_fetch_array($result)) {

            $i++;
            if ($i % 2 == 0) {
                echo "</tbody>";
                echo "<tr onClick='getValue($i);'>";
                echo "<td align='center' class='TableField2'>" . $i . "</td>";
                echo "<td  align='center' class='TableField2'><div id='madv$i'>" . $row['MA_DON_VI'] . "</div></td>";
                echo "<td  align='left' class='TableField2'><div id='tendv$i'>" . $row['TEN_DON_VI'] . "</div></td>";
                echo "<td  align='left' class='TableField2'><div id='diachidv$i'>" . $row['DIA_CHI_DV'] . "</div></td>";
                echo "<td  align='left' class='TableField2'><div id='lienhedv$i'>" . $row['LIEN_HE_DV'] . "</div></td>";
                echo "<td  align='left' class='TableField2'><div id='tentk$i'>" . $row['TEN_TK'] . "</div></td>";
                echo "<td  align='left' class='TableField2'><div id='matkhau$i'>" . $row['MAT_KHAU'] . "</div></td>";
                echo "<td  align='left' class='TableField2'><div id='quyen$i'>" . $row['QUYEN'] . "</div></td>";
        
                echo "</tr>";
            } else {
                echo "</tbody>";
                 echo "<tr onClick='getValue($i);'>";
                echo "<td align='center' class='TableField'>" . $i . "</td>";
                echo "<td  align='center' class='TableField'><div id='madv$i'>" . $row['MA_DON_VI'] . "</div></td>";
                echo "<td  align='left' class='TableField'><div id='tendv$i'>" . $row['TEN_DON_VI'] . "</div></td>";
                echo "<td  align='left' class='TableField'><div id='diachidv$i'>" . $row['DIA_CHI_DV'] . "</div></td>";
                echo "<td  align='left' class='TableField'><div id='lienhedv$i'>" . $row['LIEN_HE_DV'] . "</div></td>";
                echo "<td  align='left' class='TableField'><div id='tentk$i'>" . $row['TEN_TK'] . "</div></td>";
                echo "<td  align='left' class='TableField'><div id='matkhau$i'>" . $row['MAT_KHAU'] . "</div></td>";
                echo "<td  align='left' class='TableField'><div id='quyen$i'>" . $row['QUYEN'] . "</div></td>";
                echo "</tr>";
            }
        }
        echo "</tbody>";
        echo "<tr>";
        echo "<td align='left' colspan='9'><span style=' color:#008000'>Tổng số đơn vị: $num";
        echo "</span></td>";
        echo "<td align='right' colspan='2'><font color='green'>";
        echo "</font></td>";
        echo "</tr>";
        echo "</table></td>";
        echo "</tr>";
        echo "</table>";
        //}
        //}
        ?>
    </form>
    <!-- Het bang -->
</p>
<p>&nbsp;
</p>
</div>
</body>
</html>
